#pragma once

#include "BulletData.h"

class BulletFireStrategy {
public:
	virtual void update(BulletData* data) = 0;
};

class BulletFireStraightStategy : public BulletFireStrategy {
public:
	virtual void update(BulletData* data) {
		data->getRect()->X += data->getRect()->Vx;
		data->getRect()->Y += data->getRect()->Vy;
	}
};

class BulletFireHalfDownStrategy : public BulletFireStrategy {
protected:
	bool isSet;
public:
	BulletFireHalfDownStrategy() {
		isSet = false;
	}

	virtual void update(BulletData* data) {
	    data->getRect()->X += data->getRect()->Vx;
		data->getRect()->Y += data->getRect()->Vy;

		if (isSet) return;
		isSet = true;

		double deltax = data->rect->X - data->target->X;
		if (deltax > 300) {
			data->getRect()->Vx = -2;
			data->getRect()->Vy = 0;
		} else if (deltax <= 300 && deltax > 100) {
			data->getRect()->Vx = -2;
			data->getRect()->Vy = -1;
		} else {
			data->getRect()->Vx = -1;
			data->getRect()->Vy = -2;
		}
	}
};

class BulletFireSinCosStrategy : public BulletFireStrategy {
public:
	double angle;

	BulletFireSinCosStrategy() {
		angle = 0;
	}

	virtual void update(BulletData* data) {
		data->getRect()->X = 30 * ((float)sin(angle + M_PIl / 2)) + data->startX - 30 + angle * 2 * data->getRect()->Vx;
		data->getRect()->Y = 30 * ((float)cos(angle + M_PIl / 2)) + data->startY + angle * 3 * data->getRect()->Vy;
		angle += 0.505;
	}
};

class BulletFireParapol4Strategy : public BulletFireStrategy {
public:
	double ax, ay;

	BulletFireParapol4Strategy() {
		ay = 0;
		ax = 3;
	}

	virtual void update(BulletData* data) {
		ay = ay > 2 ? ay + 0.25 : ay + 0.1;

		data->getRect()->Y-= ay;
		data->getRect()->X -= ax;
	}
};

class BulletFireParapol5Strategy : public BulletFireParapol4Strategy {
public:

	BulletFireParapol5Strategy() : BulletFireParapol4Strategy() {
		ax = 4;
	}
};

class BulletFireParapol6Strategy : public BulletFireParapol4Strategy {
public:
	BulletFireParapol6Strategy() : BulletFireParapol4Strategy() {
		ax = 6;
	}
};